<!--
 @description
 @fileName Detail.vue
 @author zengqiongying
 @created 2023/04/21 12:44:44
-->
<template>
  <div>
    <Card>
      <DealerCell :detail="dealerData" />
    </Card>
    <Card>
      <Cell
        title="是否需要其他业务客户经理接收知晓"
        default-value="--"
        readonly
        :modelValue="getBooleanLabel(detail.isOtherReceiveManagerKnow)"
      />
      <template v-if="[1, '1'].includes(detail.isOtherReceiveManagerKnow)">
        <Cell title="接收客户经理" default-value="--" readonly :modelValue="detail.receiveManagerName" />
        <template v-if="!!detail.receiveManagerCode">
          <Cell :modelValue="detail.receiveManagerCode" title="接收客户经理编码" readonly />
          <Cell :modelValue="detail.receiveManagerTypeName" title="接收客户经理类型" readonly />
          <Cell :modelValue="detail.receiveManagerTel" title="接收客户经理电话" readonly />
        </template>
      </template>
      <Cell title="提报意见" is-column custom :right="false" :modelValue="detail.submitAnOpinion" readonly />
    </Card>

    <Card title="经销商-合作终止信息">
      <Cell
        title="合作终止原因"
        :modelValue="cooperationEndDTO.reason"
        default-value="--"
        is-column
        custom
        divider
        :right="false"
      />
      <Cell
        title="合作终止类型"
        :modelValue="cooperationEndDTO.type"
        default-value="--"
        readonly
        dict-type-code="CTM_COOPERATE_END_TYPE"
      />
      <Cell
        v-if="cooperationEndDTO.type === 'C'"
        title="是否转让销量"
        :modelValue="getBooleanLabel(cooperationEndDTO.isTransferSales)"
        default-value="--"
        readonly
      />
      <Cell
        title="未完成配送订单处理方式"
        :modelValue="cooperationEndDTO.distributionType"
        default-value="--"
        readonly
        dict-type-code="CTM_TOBE_DISTRIBUTION_ORDER_PROCESS_TYPE"
      />
      <Cell
        title="装修返利是否到期"
        :modelValue="getBooleanLabel(cooperationEndDTO.isRebateMaturity)"
        default-value="--"
        readonly
      />
      <Cell
        title="是否有未交订货"
        default-value="--"
        readonly
        :modelValue="getBooleanLabel(cooperationEndDTO.isUnfulfilledOrder)"
      />
      <Cell
        title="未交订货数量是否已提交"
        :modelValue="getBooleanLabel(cooperationEndDTO.isUnfulfilledOrderSubmit)"
        default-value="--"
        readonly
      />
      <Cell
        title="是否已开发新商家"
        :modelValue="getBooleanLabel(cooperationEndDTO.isDevelopNewCustomer)"
        default-value="--"
        readonly
      />

      <Cell
        title="新商家概况描述"
        :modelValue="cooperationEndDTO.newCustomerDescribe"
        default-value="--"
        is-column
        custom
        divider
        :right="false"
      />
      <Cell
        title="备注"
        :modelValue="cooperationEndDTO.remark"
        default-value="--"
        is-column
        custom
        divider
        :right="false"
      />
    </Card>

    <Card v-if="cooperationEndDTO.type === 'C'" title="经销商-门店数据">
      <OriginalStore ref="refOrginalStore" :changeCode="detail.code" :dataList="shopBusinessDTOS" :readonly="true" />
    </Card>
    <Card title="经销商-未完结的门店建设数据">
      <ShopConstructItem v-if="shopConstructDTOS.length > 0" :list="shopConstructDTOS" :dictData="dictData" readonly />
      <qmp-empty v-if="shopConstructDTOS.length === 0" description="暂无门店建设数据" image-size="60px" />
    </Card>

    <Card v-if="decorateEnterpriseDTO && decorateEnterpriseDTO.code" title="经销商-关联轻居客户">
      <DisCustomerDeal v-model="decorateEnterpriseDTO" readonly />
    </Card>

    <Card title="附件上传">
      <template v-if="cooperationEndDTO.type === 'A'">
        <Cell is-column custom title="最近一次整改通知书" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS072" :objectId="id" type-code="ACCESS072" readonly />
          <div v-if="attachment.ACCESS072.length === 0">暂无文件</div>
        </Cell>
      </template>
      <template v-if="cooperationEndDTO.type === 'B'">
        <Cell is-column custom title="自愿放弃说明书" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS082" :objectId="id" type-code="ACCESS082" readonly />
          <div v-if="attachment.ACCESS082.length === 0">暂无文件</div>
        </Cell>
        <Cell is-column custom title="商家手持身份证" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS083" :objectId="id" type-code="ACCESS083" readonly />
          <div v-if="attachment.ACCESS083.length === 0">暂无文件</div>
        </Cell>
      </template>

      <template v-if="cooperationEndDTO.type === 'C'">
        <Cell is-column custom title="交接证明" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS085" :objectId="id" type-code="ACCESS085" readonly />
          <div v-if="attachment.ACCESS085.length === 0">暂无文件</div>
        </Cell>
        <Cell is-column custom title="关系证明" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS086" :objectId="id" type-code="ACCESS086" readonly />
          <div v-if="attachment.ACCESS086.length === 0">暂无文件</div>
        </Cell>
        <Cell is-column custom title="交接双方现场签订照片" :right="false" required>
          <AttachmentUpload v-model="attachment.ACCESS111" :objectId="id" type-code="ACCESS111" readonly />
          <div v-if="attachment.ACCESS111.length === 0">暂无文件</div>
        </Cell>
      </template>
    </Card>
    <Card title="BPM审批信息">
      <Cell title="申请人" :modelValue="detail.createBy" default-value="--" readonly />
      <Cell
        title="申请时间"
        :modelValue="parseTime(detail.createTime, '{y}年{m}月{d}日')"
        default-value="--"
        readonly
      />
      <Cell title="BPM单号" :modelValue="detail.applyNo" default-value="--" readonly />
      <div v-for="(v, i) in detail.opinionDTOS" :key="i" class="group-box">
        <Cell title="步骤名" :modelValue="v.strStepName" default-value="--" custom readonly />
        <Cell title="操作时间" :modelValue="v.dtCreateDate" default-value="--" readonly />
        <Cell title="操作人" :modelValue="v.strApproverName" default-value="--" readonly />
        <Cell title="操作状态" :modelValue="v.strAction" default-value="--" readonly />
        <Cell title="意见留言" :modelValue="v.strComments" default-value="--" custom readonly />
      </div>
    </Card>
  </div>
</template>

<script lang="ts">
  import { computed, defineComponent, toRefs, reactive, watch } from 'vue'
  import Card from '@/components/Card/index.vue'
  import Cell from '@/components/Cell/index.vue'
  import DealerCell from '@/components/DealerCell/index.vue'
  import AttachmentUpload from '@/components/AttachmentUpload/index.vue'
  import DisCustomerDeal from './DisCustomerDeal.vue'
  import ShopConstructItem from './ShopConstructItem.vue'
  import OriginalStore from './OriginalStore.vue'
  import { detail } from '@/apis/dealerMarketing/Termination'
  import { getDictList } from '@/apis/dataDict'
  import { parseTime } from '@/utils'

  interface datasModle {
    detail: any
    attrFileList: any[]
    dictData?: any
    attachment: any
  }
  export default defineComponent({
    name: 'TerminationDetailInfo',
    components: { Card, Cell, DealerCell, DisCustomerDeal, ShopConstructItem, OriginalStore, AttachmentUpload },
    props: {
      id: {
        type: String,
        default: ''
      }
    },
    setup(props, ctx) {
      const datas = reactive<datasModle>({
        dictData: {
          BELONG_STAGE: [],
          BOOLEANS: [],
          CTM_SHOP_CONS_DATA_PROCESS_TYPE: []
        },
        attrFileList: [],
        detail: {},
        attachment: {
          ACCESS072: [],
          ACCESS082: [],
          ACCESS083: [],
          ACCESS085: [],
          ACCESS086: [],
          ACCESS111: []
        } // 附件
      })
      const dealerData = computed(() => {
        const d: any = datas.detail || {}
        return {
          code: d.customerCode || '',
          name: d.customerName || '',
          officeCode: d.officeCode || '',
          officeName: d.officeName || '',
          createBy: d.createBy || ''
        }
      })
      const shopBusinessDTOS = computed(() => {
        return datas.detail?.shopBusinessDTOS || []
      })

      // 门店建设
      const shopConstructDTOS = computed(() => {
        return datas.detail?.shopConstructDTOS || []
      })

      // 合作终止处理
      const cooperationEndDTO = computed(() => {
        return datas.detail?.cooperationEndDTO || {}
      })

      // 轻居客户信息
      const decorateEnterpriseDTO = computed(() => {
        const dto = datas.detail?.decorateEnterpriseDTO || {}
        return dto
      })

      const initDictData = async () => {
        const BELONG_STAGE = await getDictList('BELONG_STAGE')
        const BOOLEANS = await getDictList('BOOLEANS')
        const CTM_SHOP_CONS_DATA_PROCESS_TYPE = await getDictList('CTM_SHOP_CONS_DATA_PROCESS_TYPE')
        datas.dictData.BELONG_STAGE = BELONG_STAGE
        datas.dictData.BOOLEANS = BOOLEANS
        datas.dictData.CTM_SHOP_CONS_DATA_PROCESS_TYPE = CTM_SHOP_CONS_DATA_PROCESS_TYPE
      }

      const getBooleanLabel = (code: any) => {
        if ([undefined, null, ''].includes(code)) return ''
        if (datas.dictData.BOOLEANS) {
          const obj = datas.dictData.BOOLEANS.find((v: any) => v.dictCode === `${code}`)
          return obj?.dictName || code
        }
        return code
      }

      const getDetail = async () => {
        const id = `${props.id}`
        detail(id).then((res) => {
          datas.detail = res.data
          ctx.emit('data-change', res.data)
        })
      }
      watch(
        () => props.id,
        () => {
          getDetail()
        },
        {
          immediate: true
        }
      )
      initDictData()
      return {
        ...toRefs(datas),
        dealerData,
        cooperationEndDTO,
        decorateEnterpriseDTO,
        getBooleanLabel,
        parseTime,
        shopConstructDTOS,
        shopBusinessDTOS
      }
    }
  })
</script>
<style lang="less" scoped></style>
